﻿using System.Linq;
using System.Web.Mvc;
using E_Ticaret.Models;

namespace E_Ticaret.Controllers
{
    public class MyController : BaseController
    {
        //public Customer CurrentCustomer;
        //protected override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    base.OnActionExecuting(filterContext);
        //    var customer = (Customer)Session["loginkey"];
        //    if (filterContext.ActionDescriptor.ActionName != "Login")
        //    {
        //        if (Session["loginkey"] == null || customer == null)
        //        {
        //            filterContext.Result = RedirectToAction("Login", "My");
        //        }
        //        else
        //        {
        //            CurrentCustomer = customer;
        //        }
        //    }
        //}
        [HttpGet]
        public ActionResult Login()
        {
            ViewBag.Title = "Giriş Yap";
            return View();
        }
        [HttpPost]
        public ActionResult Login(Customer cust)
        {
            if (ModelState.IsValid)
            {
                var musterim = Db.Customers.SingleOrDefault(c => c.EmailAdres.Equals(cust.EmailAdres) && c.Password.Equals(cust.Password));
                if (musterim != null)
                {
                    Session["loginkey"] = musterim;
                    return RedirectToAction("Index", "Home");
                }
                else
                {

                }
            }
            ViewBag.Title = "Giriş Yap";
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

    }
}
